from django.contrib.auth.models import AnonymousUser

def common_context(self):
    return {
        'charset'     : self.site_charset(),
        'content_type': self.site_content_type(),
        'language'    : self.site_language(),
        'language_dir': self.site_language_dir(),
        'site_slogan' : self.site_slogan(),
        'site_name'   : self.site_name(),
        'theme_name'  : self.site_theme_name(),
    }

def user_context(self,request):
    user    = self.get_user(request)
    context = self.common_context()
    if user.is_anonymous():
        username = user.username
    else:
        username = user.get_full_name() or user.username
    context.update({
        'is_admin'        : user.is_superuser,
        'is_anonymous'    : user.is_anonymous(),
        'is_authenticated': user.is_authenticated(),
        'user'            : user,
        'username'        : username,
    })
    return context

